<template>
  <div class="app-container">
    <el-form
      :model="queryParams"
      ref="queryForm"
      size="small"
      :inline="true"
      v-show="showSearch"
      label-width="68px"
    >
      <el-form-item label="会员昵称" prop="memberName">
        <el-input
          v-model="queryParams.memberName"
          placeholder="请输入会员昵称"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="手机号码" prop="phonenumber">
        <el-input
          v-model="queryParams.phonenumber"
          placeholder="请输入手机号码"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="创建时间">
        <el-date-picker
          v-model="dateRange"
          style="width: 240px"
          value-format="yyyy-MM-dd HH:mm:ss"
          type="datetimerange"
          range-separator="-"
          start-placeholder="请选择"
          end-placeholder="请选择"
        ></el-date-picker>
      </el-form-item>
      <el-form-item>
        <el-button
          type="primary"
          icon="el-icon-search"
          size="mini"
          @click="handleQuery"
          >搜索</el-button
        >
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery"
          >重置</el-button
        >
      </el-form-item>
    </el-form>
    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button type="primary" plain size="mini" @click="handleSel(0)"
          >全部({{ raiNum.allStatusNum }})</el-button
        >
      </el-col>
      <el-col :span="1.5">
        <el-button type="primary" plain size="mini" @click="handleSel(1)"
          >待支付({{ raiNum.waitPayStatusNum }})</el-button
        >
      </el-col>
      <el-col :span="1.5">
        <el-button type="primary" plain size="mini" @click="handleSel(2)"
          >已支付({{ raiNum.doPayStatusNum }})</el-button
        >
      </el-col>
      <el-col :span="1.5">
        <el-button type="primary" plain size="mini" @click="handleSel(3)"
          >已取消({{ raiNum.cancelPayStatusNum }})</el-button
        >
      </el-col>
    </el-row>
    <el-table v-loading="loading" :data="postList">
      <el-table-column label="订单编号" align="center" prop="orderCode" />
      <el-table-column label="创建时间" align="center" prop="createTime" />
      <el-table-column label="支付时间" align="center" prop="payTime" />
      <el-table-column label="订单金额" align="center" prop="orderMoney" />
      <el-table-column label="会员昵称" align="center" prop="memberName" />
      <el-table-column label="手机号码" align="center" prop="phonenumber" />
      <el-table-column label="订单状态" align="center" prop="orderStatus">
        <template slot-scope="scope">
          <dict-tag
            :options="dict.type.order_type"
            :value="scope.row.orderStatus"
          />
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total > 0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />
  </div>
</template>

<script>
import { getSetMenuListAPI, getSetMenuGetRaiNumAPI } from "@/api/system/member";

export default {
  name: "membershipPackageOrder",
  dicts: ["order_type"],
  data() {
    return {
      // 遮罩层
      loading: false,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 1,
      // 岗位表格数据
      postList: [],
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 15,
        memberName: undefined,
        phonenumber: undefined,
        startDate: undefined,
        endDate: undefined,
        orderStatus: undefined,
      },
      dateRange: [],
      raiNum: {
        allStatusNum: 0, // 全部
        waitPayStatusNum: 0, //待支付
        doPayStatusNum: 0, //已支付
        cancelPayStatusNum: 0, //已取消
      },
    };
  },
  watch: {
    dateRange: {
      handler(newVal, oldVal) {
        if (newVal != null && newVal.length > 0) {
          this.queryParams.startDate = newVal[0];
          this.queryParams.endDate = newVal[1];
        } else {
          this.queryParams.startDate = undefined;
          this.queryParams.endDate = undefined;
        }
      },
    },
  },
  created() {
    this.getMenList();
    this.getList();
  },
  methods: {
    getMenList() {
      getSetMenuGetRaiNumAPI().then((response) => {
        if (response.code == 200) {
          this.raiNum = response.data || {
            allStatusNum: 0, // 全部
            waitPayStatusNum: 0, //待支付
            doPayStatusNum: 0, //已支付
            cancelPayStatusNum: 0, //已取消
          };
        }
      });
    },
    handleSel(val) {
      if (val == 0) {
        this.queryParams.orderStatus = undefined;
      } else {
        this.queryParams.orderStatus = val;
      }
      this.getList();
    },
    getList() {
      this.loading = true;
      getSetMenuListAPI(this.queryParams).then((response) => {
        if (response.code == 200) {
          this.postList = response.rows;
          this.total = response.total;
          this.loading = false;
        }
      });
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.dateRange = [];
      this.queryParams.orderStatus = undefined;
      this.resetForm("queryForm");
      this.handleQuery();
    },
  },
};
</script>
